#include <iostream>
using namespace std;

class Animal
{
public:
  Animal()
  {
    cout << "Animal 构造" << endl;
  }
  // 纯虚函数
  virtual void speak() = 0;

  // 利用虚构可以解决 父类指针释放子类对象时不干净的问题
  // virtual ~Animal()
  // {
  //   cout << "Animal 析构" << endl;
  // }
  // 纯虚析构  需要声明也需要实现
  // 有了纯虚析构之后，也变成抽象类，无法实例对象
  virtual ~Animal() = 0;
};

Animal::~Animal() {
  cout << "Animal 纯虚析构" << endl;
}

class Cat : public Animal
{
public:
  string *m_name;
  Cat(string name)
  {
    cout << "Cat 构造" << endl;
    m_name = new string(name);
  }
  virtual void speak()
  {
    cout << *m_name << ": 喵~" << endl;
  }

  ~Cat()
  {
    cout << "Cat 析构" << endl;
    if (m_name != NULL)
    {
      delete m_name;
    }
  }
};

void test01()
{
  Animal *animal = new Cat("tom");

  animal->speak();
  delete animal;
}

int main(int argc, char const *argv[])
{

  test01();

  return 0;
}